package game_FrozenBubble;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

import com.gmsi_prototype.R;

public class ResultsActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_activity_results);
        //Based on score give proper comment
        //Example - If low score: "Try relaxing a little more"
        //Show score under comment
        


        int lvlcom = ChillOut.stats.lvls_completed;
        int popped = ChillOut.stats.bbls_popped;
        int launched =  ChillOut.stats.bbls_launched;
        int spikes = ChillOut.stats.spikes;
        int loss = ChillOut.stats.lvls_total-ChillOut.stats.lvls_completed;
        double avgspikes = 0.0;
        //This comes from where ever how ever we define a score
        int scorenum = lvlcom*1000 + popped*50 + launched*-25 + spikes*-50 + loss*-250;
        
        //Comments
        String hiSpikes = "Try relaxing a little more";
        String medSpikes = "You are on track to becoming relaxed";
        String lowSpikes = "Good Job! You are managing stress well";
        //.
        //.
        double baseline = ChillOut.baseline;
        avgspikes = spikes/ChillOut.thread.TIME_GAME;
        String comment = "";
        
        if(avgspikes + ChillOut.threshold<baseline)
        	comment = lowSpikes;
        else if(spikes - ChillOut.threshold>baseline)
        	comment = hiSpikes;
        else
        	comment = medSpikes;
        
        TextView result = new TextView(this);
        TextView stats = new TextView(this);
        TextView score = new TextView(this);
        result = (TextView)findViewById(R.id.comment);        
        result.setText(comment);
        stats = (TextView)findViewById(R.id.stats);
        stats.setText("Levels Completed: "+lvlcom+"\n" +
        			  "Bubbles Popped: "+popped+"\n" +
        			  "Bubbles Shot: "+launched+"\n" +
        			  "Spikes: "+spikes+"\n" +
        			  "Frozenified: "+loss+"\n\n");
 
        score = (TextView)findViewById(R.id.score);
        score.setTextSize(20);
        score.setText("SCORE: "+scorenum);
        
        //Floating Animation
        Animation floating = AnimationUtils.loadAnimation(this, R.anim.floating);
        
        //Results Button        
        final Button results = (Button)findViewById(R.id.resultsButton);
        results.startAnimation(floating);
        
        results.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {            
            	
            	//Start activity of graph here
				Intent results_intent = new Intent(ResultsActivity.this, GraphResults.class);
				startActivity(results_intent);
           
            }
        });
        
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK))
        {
        	finish();
        	
        	//Attempting to go back to the Title Screen
			Intent title_intent = new Intent(ResultsActivity.this, ChillOut.class);
			startActivity(title_intent);

        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
    }
}
